<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="base.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>BBS-论坛注册系统</title>
		<link rel="stylesheet" type="text/css" href="style/style.css" />
		<script type="text/javascript" src="${basePath }/script/jquery-1.3.2.min.js"></script>
		<script type="text/javascript" charset="utf-8" src="${basePath }/script/kindeditor-min.js"></script>
		<script type="text/javascript">
			KE.show({
				id : 'sign',
					allowPreviewEmoticons : true,
					allowUpload : true,
					imageUploadJson:'${basePath}/script/ke/upload_json.jsp',
					items : [
					'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
					'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
					'insertunorderedlist', '|', 'emoticons', 'image', 'link']
			});
		</script>
		
		<script type="text/javascript">
		
			var xmlHttp;
			function createXmlHttpRequest(){
				if(window.ActiveXObject){
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}else{
					xmlHttp = new XMLHttpRequest();
				}
			}
			function checkUserName(name){
				regexp = /([\w]){4,12}$/;
				if(name.value.trim() == ""){
					document.getElementById("namemsg").innerHTML="用户名不能为空";
					return false;
				}else if(!regexp.test(name.value.trim())){
					document.getElementById("namemsg").innerHTML="用户名应由4-12个字符组成";
					return false;
				}else{
					createXmlHttpRequest();
					xmlHttp.open("GET","user.jspx?_method=check&name="+name.value.trim(),true);
					//xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlHttp.onreadystatechange = callback;
					xmlHttp.send();
				}
				
			}
			function callback(){
				if(xmlHttp.readyState == 4){
					if(xmlHttp.status == 200){
						var result = xmlHttp.responseText;
						if("ok"== result){
							document.getElementById("namemsg").innerHTML="验证通过";
							return true;
						}else if("error" == result){
							document.getElementById("namemsg").innerHTML="此用户名已被注册";
							return false;
						}
					}
				}
			}
			
			function checkPassword(password){
				regexp1 = /([\w]){6,15}$/;
				if(password.value.trim() == ""){
					document.getElementById("passwordmsg").innerHTML="密码不能为空";
					return false;
				}else if(!regexp1.test(password.value.trim())){
					document.getElementById("passwordmsg").innerHTML="密码由6-15个字符组成";
					return false;
				}else{
					document.getElementById("passwordmsg").innerHTML="验证通过";
					return true;
				}
			}
			function checkEmail(email){
				regexp2 = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
				if(email.value.trim() == ""){
					document.getElementById("emailmsg").innerHTML="email不能为空";
					return false;
				}else if(!regexp2.test(email.value.trim())){
					document.getElementById("emailmsg").innerHTML="请输入正确的Email格式";
					return false;
				}else{
					document.getElementById("emailmsg").innerHTML="验证通过";
					return true;
				}
			}
			function checkTel(tel){
				regexp3 = /^0*(13|15)\d{9}$/;
				if(tel.value.trim() == ""){
					document.getElementById("telmsg").innerHTML="tel不能为空";
					return false;
				}else if(!regexp3.test(tel.value.trim())){
					document.getElementById("telmsg").innerHTML="仅支持130-150号码段";
					return false;
				}else{
					document.getElementById("telmsg").innerHTML="验证通过";
					return true;
				}
			}
			function checkValidateCode(code){
				if(code.value.trim() == ""){
					document.getElementById("codemsg").innerHTML="请输入验证码";
				}else{
					createXmlHttpRequest();
					xmlHttp.open("GET","user.jspx?_method=checkcode&code="+code.value.trim(),true);
					//xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlHttp.onreadystatechange = codemsg;
					xmlHttp.send();
				}
			}
			function codemsg(){
				if(xmlHttp.readyState == 4){
					if(xmlHttp.status == 200){
						var result = xmlHttp.responseText;
						if("ok"== result){
							document.getElementById("codemsg").innerHTML="验证通过";
							return true;
						}else if("error" == result){
							document.getElementById("codemsg").innerHTML="验证码输入错误";
							return false;
						}
					}
				}
			}
			function checkFlag(){
				if(KE.isEmpty('sign')){
					document.getElementById("signmsg").innerHTML="个性签名不能为空";
					return false;
				}
				return checkUserName(name)&&checkPassword(password)&&checkEmail(email)&&checkTel(tel)&&checkValidateCode(code);
			}
		</script>
		
	</head>

	<body>
		<%@include file="template/top.jsp"%>
			
		<div id="contain">
		<div class="nav">
    	<a href="index.jspx">论坛首页</a>
        &gt;&gt;
       注册新用户
  </div>	
			<div class="board">
				<div class="board_title">
					注册新用户
				</div>
				<div class="reg_login">
					<div class="left">
						<c:if test="${not empty msg }">
							<div id="nameerror" style="width: 300px;">
								${msg }
							</div>
							<c:remove var="msg" scope="session" />
						</c:if>
						<form action="user.jspx" method="post" id="regForm" onsubmit="return checkFlag()" >
							<input type="hidden" name="_method" value="reg" />
							<label>
								用户名：
							</label>
							<input type="text" name="name" id="name" class="text" onblur="checkUserName(this)"/><span id="namemsg" class="namemsg"></span>
							<label>
								密码：
							</label>
							<input type="password" name="password" id="password"  class="text" onblur="checkPassword(this)" /><span id="passwordmsg"></span>
							<label>
								电子邮件：
							</label>
							<input type="text" name="email" id="mail"  class="text" onblur="checkEmail(this)"/><span id="emailmsg"></span>
							<label>
								性别：
							</label>
							<input type="radio" name="sex" value="1" id="sex" checked="checked"/>
							男
							<input type="radio" name="sex" value="0" id="sex"/>
							女
							<span id="sexmsg"></span>
							<br />
							<label>
								电话：
							</label>
							<input type="text" name="tel" id="tel" class="text" onblur="checkTel(this)"/><span id="telmsg"></span>
							<label>
								个性签名：
							</label>
							<textarea id="sign" style="width:430px;height:200px" onblur="checkSign()"></textarea><span id="signmsg"></span>
							<label>验证码</label>
							<input type="text" name="validatecode" class="text" onblur="checkValidateCode(this)" />
							<span id="codemsg"></span>
							<div><img name="codeimg" src="jcaptcha.jpg"/>
							</div>
							<div>
								<input type="submit" value="注册" />
							</div>
						</form>
					</div>
					<div class="right">
						<h3>
							已有账户
						</h3>
						已经有了一个账户?直接<a href="index.jspx?_method=login">登录</a>
						
					</div>
				</div>
			</div>
		</div>

		<%@include file="template/footer.jsp"%>

	</body>
</html>
